#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define LagaKar ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair
#define fi first
#define se second
#define precise(ans) cout<<fixed<<setprecision(15)<<ans
#define fo(i,n) for(ll i=0;i<n;i++)
#define Fo(i,k,n) for(ll i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define sz(x) ((ll)(x).size())
#define all(x) x.begin(), x.end()
#define PI 3.1415926535897932384626
#define MOD 1000000007
#define MOD1 998244353
typedef long long ll; typedef unsigned long long ull; typedef long double lld; typedef pair<ll, ll> pii; typedef pair<ll, ll> pl; typedef vector<ll> vi; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<pii> vpii; typedef vector<pl> vpl; template <typename T> using prq_mx = priority_queue<T>; template <typename T> using prq_mn = priority_queue<T, vector<T>, greater<T>>;
const double eps = 1e-9; const ll INF = (ll) 1e9; const ll inf64 = 2e18; const ll INF64 = 9e18;
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _prll(x); cerr << endl;
#else
#define debug(x)
#endif
void _prll(ll t) {cerr << t;} void _print(ll t) {cerr << t;} void _prll(string t) {cerr << t;} void _prll(char t) {cerr << t;} void _prll(lld t) {cerr << t;} void _prll(double t) {cerr << t;} void _prll(ull t) {cerr << t;} template <class T, class V> void _prll(pair <T, V> p); template <class T> void _prll(vector <T> v); template <class T> void _prll(set <T> v); template <class T, class V> void _prll(map <T, V> v); template <class T> void _prll(multiset <T> v); template <class T, class V> void _prll(pair <T, V> p) {cerr << "{"; _prll(p.fi); cerr << ","; _prll(p.se); cerr << "}";} template <class T> void _prll(vector <T> v) {cerr << "[ "; for (T i : v) {_prll(i); cerr << " ";} cerr << "]";} template <class T> void _prll(set <T> v) {cerr << "[ "; for (T i : v) {_prll(i); cerr << " ";} cerr << "]";} template <class T> void _prll(multiset <T> v) {cerr << "[ "; for (T i : v) {_prll(i); cerr << " ";} cerr << "]";} template <class T, class V> void _prll(map <T, V> v) {cerr << "[ "; for (auto i : v) {_prll(i); cerr << " ";} cerr << "]";}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//////////////////////////////////////////////////////////////////////////////////
const ll max_N=1e6+10;
vector<ll> prime(max_N, 0);
vector<ll> aa;
void primesieve(){
prime[0] = 1;
prime[1] = 1;
for (ll i = 2; i <max_N; i++)
{
if (prime[i] == 0)
{
prime[i]=i;
for (ll j = i*i; j < max_N; j = j + i)
{
prime[j] = i;
}
}
}
for(ll i=2;i<max_N;i++){
if(prime[i]){
aa.push_back(i);
}
}
}
void chal(){
ll n;
cin>>n;
vl aa(n);
map<ll,ll> bb;
ll ans=0;
fo(i,n){
cin>>aa[i];
ll x=aa[i];
ll res=1;
while(x>1){
ll p=prime[x];
if(p==0){
// cout<<x<<" "<<-1<<endl;
exit(0);
}
ll c=0;
while(x>1 && x%p==0){
x=x/p;
c++;
}
if((c&1)){
res*=p;
}
}
bb[res]++;
ans=max(ans,bb[res]);
}
ll ans2=ans;
tr(it,bb){
if(it->se%2==0 && it->fi!=1){
bb[1]+=it->se;
}else{
ans2=max(ans2,it->se);
}
}
ans2=max(ans2,bb[1]);
// debug(aa);
ll q;
cin>>q;
while(q--){
ll x;
cin>>x;
if(x==0){
cout<<ans<<endl;
}else{
cout<<ans2<<endl;
}
}
// cout<<endl;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int32_t main() {
LagaKar;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("Error.txt", "w", stderr);
#endif
primesieve();
ll t; t = 1;
cin >> t;
for (ll i = 1; i <= t; i++) {
chal();
} return 0;
}
544B - Sea and Islands | 152B - Steps |
1174D - Ehab and the Expected XOR Problem | 1511A - Review Site |
1316A - Grade Allocation | 838A - Binary Blocks |
1515D - Phoenix and Socks | 1624D - Palindromes Coloring |
1552F - Telepanting | 1692G - 2Sort |
1191A - Tokitsukaze and Enhancement | 903A - Hungry Student Problem |
52B - Right Triangles | 1712A - Wonderful Permutation |
1712D - Empty Graph | 1712B - Woeful Permutation |
1712C - Sort Zero | 1028B - Unnatural Conditions |
735B - Urbanization | 746C - Tram |
1278B - A and B | 1353D - Constructing the Array |
1269C - Long Beautiful Integer | 1076A - Minimizing the String |
913C - Party Lemonade | 1313A - Fast Food Restaurant |
681A - A Good Contest | 1585F - Non-equal Neighbours |
747A - Display Size | 285A - Slightly Decreasing Permutations |